//
//  UIViewController+BSKToast.m
//  MicroMemory
//
//  Created by rimi on 16/7/18.
//  Copyright © 2016年 BlueSky. All rights reserved.
//

#import "UIViewController+BSKToast.h"
#import "BSKconsts.h"

@implementation UIViewController (BSKToast)
-(void)MakeToast:(NSString *)text WithTime:(double)seconds{
	__block UILabel * toast = [[UILabel alloc]init];
	toast.alpha = 0;
	[self.view addSubview:toast];
	toast.numberOfLines = 0;
	toast.text = text;
	[toast sizeToFit];
	toast.bounds = CGRectMake(0, 0, toast.bounds.size.width+30, toast.bounds.size.height+20);
	toast.center = CGPointMake(ScreenWidth/2, ScreenHeight - 200);
	toast.layer.cornerRadius = 20;
	toast.layer.masksToBounds = YES;
	toast.textAlignment = NSTextAlignmentCenter;
	toast.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.74];
	toast.textColor = [UIColor whiteColor];
	toast.transform = CGAffineTransformMakeScale(1.5, 1.5);
	[UIView animateWithDuration:0.25 animations:^{
		toast.alpha = 1;
		toast.transform = CGAffineTransformMakeScale(1, 1);
	} completion:nil];
	
	dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(seconds * NSEC_PER_SEC));
	dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
		
		[UIView animateWithDuration:0.25 animations:^{
			toast.alpha = 0;
		} completion:^(BOOL finished) {
			[toast removeFromSuperview];
		}];
		
	});
	
}
@end
